# Maintainer: Martell Malone <martellmalone@gmail.com>

_realname=binwalk
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}") #"${MINGW_PACKAGE_PREFIX}-python2-${_realname}"
pkgver=2.1.1
pkgrel=1
pkgdesc="A tool for searching a given binary image for embedded files (mingw-w64)"
arch=('any')
url="http://binwalk.org"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-bzip2"
         "${MINGW_PACKAGE_PREFIX}-libsystre"
         "${MINGW_PACKAGE_PREFIX}-xz"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         #'tar'
         #'git'
         )
source=(${_realname}-${pkgver}.tar.gz::https://github.com/devttys0/${_realname}/archive/v${pkgver}.tar.gz)
sha256sums=('1b70a5b03489d29f60fef18008a2164974234874faab48a4f47ec53d461d284a')

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=;--install-purelib=;--install-data=" \
  ${MINGW_PREFIX}/bin/python3 setup.py build
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=;--install-purelib=;--install-data=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX#\/} --root="${pkgdir}" --optimize=1 --skip-build
  install -m 644 -D "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  # fix python command in files
  sed -e "s|${PREFIX_WIN}/bin/|/usr/bin/env |g" -i "${pkgdir}${MINGW_PREFIX}"/bin/binwalk
}
